package com.dayuanit.dy17.atm.util;

import java.util.Random;

public class CardUtils {

    public static String createCardNum() {
        Random random = new Random();
        StringBuilder sx = new StringBuilder();

        for (int i = 0; i < 5; i ++) {
            int number = random.nextInt(10);
            sx.append(number);
        }
        return sx.toString();
    }

    public static String formatCardNum(String cardNum) {
        StringBuilder sx = new StringBuilder();
        sx.append(cardNum.substring(0, 1))
                .append("***")
                .append(cardNum.substring(cardNum.length() - 2, cardNum.length()));
        return sx.toString();
    }

    public static void main(String[] args) {
        String card = "12345";

        System.out.println(card.substring(0, 1));
        System.out.println(card.substring(card.length()-2, card.length()));

        StringBuilder sx = new StringBuilder();
        sx.append(card.substring(0, 1))
                .append("***")
                .append(card.substring(card.length()-2, card.length()));
        System.out.println(sx.toString());
    }
}
